//
//  PictureViewCell.m
//  Happy to chat
//
//  Created by lanou3g on 15/12/8.
//  Copyright © 2015年 LL. All rights reserved.
//

#import "PictureViewCell.h"
#import "UIImageView+WebCache.h"
@implementation PictureViewCell
//赋值
- (void)setModel:(PictureModel *)model{
    _model = model;
    self.wbodyLable.text = model.wbody;
    [self.wpic_middleImg sd_setImageWithURL:[NSURL URLWithString:model.wpic_middle] placeholderImage:[UIImage imageNamed:@"7"]];
}

- (IBAction)Action4Collection:(UIButton *)sender {
  
    
    AVUser *current =  [AVUser currentUser];
    
//    NSData *imageData = UIImagePNGRepresentation(self.wpic_middleImg.image);
//    AVFile *imageFile = [AVFile fileWithName:@"image.png" data:imageData];
//    [imageFile saveInBackground];
//    
//    AVObject *userPost = [AVObject objectWithClassName:@"Image"];
//    [userPost setObject:imageFile            forKey:@"image"];
//    [userPost setObject:current.username            forKey:@"name"];
//    [userPost saveInBackground];
//
   
    NSMutableData *data = [NSMutableData data];
    
    //创建归档对象
    NSKeyedArchiver *archive = [[NSKeyedArchiver alloc]initForWritingWithMutableData:data];
    //归档
    [archive encodeObject:_model forKey:@"secret"];
    //完成归档
    [archive finishEncoding];
    
    AVFile *file = [AVFile fileWithName:@"model.text" data:data];
    
    [file saveInBackground];
    
    AVObject *userPost = [AVObject objectWithClassName:@"ImageModel"];
    [userPost setObject:file forKey:@"model"];
     [userPost setObject:current.username            forKey:@"name"];
    
    [userPost saveInBackground];
    
    
 
    NSLog(@"收藏了%@",current.username);
    
}


- (IBAction)Action4Share1:(UIButton *)sender {
    NSLog(@"fenxing");
}




- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
